Repository navigation
Conversation
There was a problem hiding this comment.
Important
The new set misses the immediate address space — one TypeGPU itself emits as var<immediate> — so the shadowing bug this PR fixes is still reachable there.
Reviewed changes
templateEnumerants(packages/typegpu/src/nameUtils.ts) — adds the five core address spaces, three access modes, and 40 texel formats as reserved enumerants, deliberately kept out ofbannedTokensso struct-member names stay legal.- Namespace wiring (
packages/typegpu/src/core/resolve/namespace.ts) — seedstakenGlobalIdentifierswith the new set;makeUniqueIdentifierconsults it for both global and block scopes. - Tests (
packages/typegpu/tests/namespace.test.ts) — a snapshot that fails onmain(mutableread_write, private varrgba8unorm, localwrite), plus a guard that struct members namedread/writeare untouched.
ℹ️ Nitpicks
- The texel-format half of
templateEnumerantsre-lists the 40 members ofStorageTextureFormats(packages/typegpu/src/core/texture/textureFormats.ts:14); a format added there in future won't be picked up here, silently reintroducing this bug for that format.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Good catch on |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed only what landed since the previous Pullfrog review (3b37cb99 → bf037898): the commit that closes the immediate address-space gap flagged last time.
immediatereserved (packages/typegpu/src/nameUtils.ts) — adds theimmediateaddress space totemplateEnumerants, closing the last shadowing path for an enumerant TypeGPU itself emits asvar<immediate>.- Regression test (
packages/typegpu/tests/namespace.test.ts) — assertsimmediateVar(...).$name('immediate')resolves toimmediate_1; it fails on the prior head and passes now (namespace.test.ts, 6/6).
( ◦°^°◦) 🏴☠️ Arr! The new commit be addin' immediate to the reserved enumerants, just as the last review demanded — the test now names it immediate_1, so the shadowin' bug be scuttled. Nary a fresh leak spotted, so I raised the green flag.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
A module-scope or local declaration named like an address space, access mode or texel format shadows that enumerant, so a later template such as var<storage, read_write> would refer to the declaration. Reserve them in the namespace so such names get a suffix. They stay valid as struct member names, which shadow nothing. Closes software-mansion#3065
bf03789 to
ff31e37
Compare

Fixes #3065.
Cause
WGSL's address spaces (
function,private,workgroup,uniform,storage), access modes (read,write,read_write) and texel formats (rgba8unorm, …) are predeclared enumerants, and a declaration can shadow them. Template parameters refer to them by name:var<storage, read_write>,texture_storage_2d<rgba8unorm, write>. Before this change, a buffer namedread_writecame out asand any later
read_writein a template resolves to that variable. A locallet write = ...does the same inside its function.uniformandstoragewere already inbannedTokens. The other enumerants weren't reserved anywhere.Fix
nameUtils.tsgets atemplateEnumerantsset: the five address spaces, the three access modes, and every texel format inStorageTextureFormats(the 17 core WGSL formats plus thetexture-formats-tier1ones).takenGlobalIdentifiers, next tobannedTokensandbuiltins.makeUniqueIdentifierchecks the set for both global and block scope, so module-scope and local names get a_1suffix like the other reserved words.I kept them out of
bannedTokenson purpose.bannedTokensis also whatvalidatePropchecks for struct members and what function argument names are checked against, so adding them there would maked.struct({ read: d.u32 })throw. A struct member never shadows a module-scope name, soread/writethere are valid WGSL and keep working. If you'd rather have them inbannedTokenslikeuniformandstorage, that's a one-line move.Tests
tests/namespace.test.ts:read_write, a private var namedrgba8unormand a localwriteresolve toread_write_1,rgba8unorm_1andwrite_1. Onmainthis test fails: the names come out unsuffixed.d.struct({ read: d.u32, write: d.u32 })still resolves with its member names.packages/typegpu:vitest rungives 192 files, 2733 passed. oxfmt is clean.